<template>
  <d2-container>
    <template slot="header">
      <el-form
        :gutter="24"
        ref="search-box"
        :model="mainQuery"
        label-position="left"
        :inline="true"
        label-width="90px"
      >
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="商户号：" size="mini">
              <el-input
                placeholder=""
                v-model="mainQuery.mchNo"
                @keyup.enter.native="handleSearch"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="订单号：" size="mini">
              <el-input
                placeholder=""
                v-model="mainQuery.tradeNo"
                @keyup.enter.native="handleSearch"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="退款状态：" size="mini">
              <el-select v-model="mainQuery.isRefund" size="small" clearable>
                <el-option
                  v-for="item in isRefundOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="冻结状态：" size="mini">
              <el-select v-model="mainQuery.isFrozen" size="small" clearable>
                <el-option
                  v-for="item in isFrozenOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="解冻状态：" size="mini">
              <el-select v-model="mainQuery.isThaw" size="small" clearable>
                <el-option
                  v-for="item in isThawOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="拒付状态：" size="mini">
              <el-select v-model="mainQuery.isDis" size="small" clearable>
                <el-option
                  v-for="item in isDisOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="通道：" size="mini">
              <el-select v-model="mainQuery.channelId" size="small" clearable>
                <el-option
                  v-for="item in channelIdOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="邮箱：" size="mini">
              <el-input
                placeholder=""
                v-model="mainQuery.cardEmail"
                @keyup.enter.native="handleSearch"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="IP：" size="mini">
              <el-input
                placeholder=""
                v-model="mainQuery.ipAddress"
                @keyup.enter.native="handleSearch"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="电话：" size="mini">
              <el-input
                placeholder=""
                v-model="mainQuery.cardFullPhone"
                @keyup.enter.native="handleSearch"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="姓名：" size="mini">
              <el-input
                placeholder=""
                v-model="mainQuery.cardFullName"
                @keyup.enter.native="handleSearch"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="时间区间：" size="mini">
          <el-date-picker
            size="small"
            v-model="dateTimeRange"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="datetimePickerOptions"
            @change="onDateTimePickerChange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>

      <div class="search-btn-box">
        <div class="left">
          变更操作：
          <el-button-group style="margin-right: 100px">
            <el-button
              class="filter-item"
              type="plain"
              @click="handleDis()"
              :loading="mainTable.loading"
              :disabled="startType != 0"
              size="mini"
              v-if="$options.filters['checkButtonAccess']('tradeOrderDis-add')"
              >拒付</el-button
            >
            <el-button
              class="filter-item"
              type="plain"
              @click="handleFrozen()"
              :loading="mainTable.loading"
              :disabled="startType != 0"
              size="mini"
              v-if="$options.filters['checkButtonAccess']('tradeOrderFrozen-add')"
              >冻结</el-button
            >
            <el-button
              class="filter-item"
              type="plain"
              @click="handleThaw()"
              :loading="mainTable.loading"
              :disabled="
                !(
                  rowInfo.isFrozen == 4 &&
                  (rowInfo.isThaw == 0 ||
                    rowInfo.isThaw == 3 ||
                    rowInfo.isThaw == 5)
                )
              "
              size="mini"
              v-if="$options.filters['checkButtonAccess']('tradeOrderThaw-add')"
              >解冻</el-button
            >
          </el-button-group>

          审核操作：
          <el-button-group style="margin-left: 0px">
            <el-button
              class="filter-item"
              type="success"
              @click="handleAudit('First')"
              :loading="mainTable.loading"
              :disabled="auditType != 1"
              size="mini"
              v-if="$options.filters['checkButtonAccess']('tradeOrderDis-handleFirstReview') &&
                    $options.filters['checkButtonAccess']('tradeOrderFrozen-handleFirstReview') &&
                    $options.filters['checkButtonAccess']('tradeOrderThaw-handleFirstReview') &&
                    $options.filters['checkButtonAccess']('tradeOrderRefund-handleFirstReview')"
              >初审</el-button
            >

            <el-button
              class="filter-item"
              type="success"
              @click="handleAudit('Second')"
              :loading="mainTable.loading"
              :disabled="auditType != 2"
              size="mini"
              v-if="$options.filters['checkButtonAccess']('tradeOrderDis-handleSecondReview') &&
                    $options.filters['checkButtonAccess']('tradeOrderFrozen-handleSecondReview') &&
                    $options.filters['checkButtonAccess']('tradeOrderThaw-handleSecondReview') &&
                    $options.filters['checkButtonAccess']('tradeOrderRefund-handleSecondReview')"
              >终审</el-button
            >
          </el-button-group>
        </div>

        <div class="right">
          <el-button
            class="filter-item"
            icon=""
            type="default"
            @click="resetMainData"
            :loading="mainTable.loading"
            size="small"
            >重置</el-button
          >
          <el-button
            class="filter-item"
            icon="el-icon-search"
            type="primary"
            @click="handleSearch"
            :loading="mainTable.loading"
            size="small"
            >查询</el-button
          >
        </div>
      </div>
    </template>

    <!--主列表数据-->
    <d2-crud
      ref="d2Crud"
      selection-row
      :options="mainTable.options"
      :index-row="mainTable.indexRow"
      :columns="mainTable.columns"
      :data="mainTable.list"
      :loading="mainTable.loading"
      :rowHandle="mainTable.rowHandle"
      @current-change="onMainCurrentChange"
      @custom-emit-handle-order="handleOrderDetail"
      @custom-emit-handle-order-log="handleOrderLog"
      @selection-change="onMainSelectionChange"
    ></d2-crud>

    <template slot="footer">
      <el-pagination
        @size-change="handleMainSizeChange"
        @current-change="handleMainPageChange"
        :current-page="mainTable.pagination.currentPage"
        :page-sizes="mainTable.pagination.pageSizes"
        :page-size="mainTable.pagination.pageSize"
        :page-count="mainTable.pagination.pageCount"
        :total="mainTable.pagination.total"
        layout="total, sizes, prev, pager, next, jumper"
        :background="true"
      >
      </el-pagination>
    </template>

    <dialog-detail
      ref="dialog-detail"
      @dialog-close="fetchMainData"
    ></dialog-detail>

    <dialog-refund
      ref="dialog-refund"
      @dialog-close="fetchMainData"
    ></dialog-refund>

    <dialog-dis ref="dialog-dis" @dialog-close="fetchMainData"></dialog-dis>

    <dialog-frozen
      ref="dialog-frozen"
      @dialog-close="fetchMainData"
    ></dialog-frozen>

    <dialog-thaw ref="dialog-thaw" @dialog-close="fetchMainData"></dialog-thaw>

    <dialog-log ref="dialog-log" @dialog-close="fetchMainData"></dialog-log>
    <dialog-audit
      ref="dialog-audit"
      @dialog-close="fetchMainData"
    ></dialog-audit>
    <dialog-upload
      ref="dialog-upload"
      @dialog-close="fetchMainData"
    ></dialog-upload>

    <dialog-review
      ref="dialog-review"
      @dialog-close="fetchMainData"
    ></dialog-review>
  </d2-container>
</template>

<script>

import ApiMain from '@/api/trade.detail';
import DialogDetail from '../detail/dialog-add';
import DialogRefund from '../refund/dialog-add';
import DialogDis from './dialog-dis';
import DialogFrozen from './dialog-frozen';
import DialogThaw from './dialog-thaw';
import DialogLog from './dialog-log';
import DialogUpload from './dialog-upload';
import DialogReview from './dialog-review';
import util from '@/libs/util.js';
import ChannelApiMain from '@/api/bank.channel';
import ThawApiMain from '@/api/trade.thaw';
import FrozenApiMain from '@/api/trade.frozen';
import DisApiMain from '@/api/trade.dis';
import { isCheckedOptions, isRefundOptions, isFrozenOptions, isShipOptions, isSettleOptions, isDisOptions, isThawOptions } from '@/const/constant';
import DatetimePickerMixin from '@/mixin/DatetimePickerMixin'
import DialogAudit from './dialog-audit';

export default {
  name: 'trade-trans',
  mixins: [
    DatetimePickerMixin,
  ],
  components: {
    'dialog-audit': DialogAudit,
    'dialog-detail': DialogDetail,
    'dialog-refund': DialogRefund,
    'dialog-dis': DialogDis,
    'dialog-frozen': DialogFrozen,
    'dialog-thaw': DialogThaw,
    'dialog-log': DialogLog,
    'dialog-upload': DialogUpload,
    'dialog-review': DialogReview,
  },
  data() {
    return {

      mainQuery: {
        mchNo: undefined,
        // terNo: undefined,
        tradeNo: undefined,
        isRefund: undefined,
        // isChecked: 2,
        isSettle: 2,
        isShip: undefined,
        isDis: undefined,
        isFrozen: undefined,
        isThaw: undefined,
        channelId: undefined,
        cardType: undefined,
        transStatus: undefined,
        cardEmail: undefined,
        cardFullName: undefined,
        cardFullPhone: undefined,
        ipAddress: undefined,
        startTime: undefined,
        endTime: undefined,
      },
      auditType: 0,
      startType: 0,
      startTypeText: "",
      mainTable: {
        loading: false,
        options: {
          border: true,
          stripe: true,
          highlightCurrentRow: true,
          emptyText: '暂无数据',
          size: 'mini',
        },
        // indexRow: {
        //   title:'序号',
        //   width: "80",
        //   align:'center'
        // },
        indexRow: null,
        allowSelect: false,
        columns: [
          // {title: 'id', key: 'id', align: 'center', showOverflowTooltip: true},
          { title: '单号', key: 'tradeNo', align: 'center', width: '180', showOverflowTooltip: true, fixed: true },
          { title: '商户号', key: 'mchNo', align: 'center', width: '180', showOverflowTooltip: true },
          {
            title: '交易金额', key: 'mchTransAmount', align: 'center', width: '120', showOverflowTooltip: true, formatter(row, column, cellValue, index) {
              return row.mchTransCurrency + ' ' + (row.mchTransAmount / 100).toFixed(2)
            }
          },
          { title: '退款状态', key: 'strIsRefund', align: 'center', width: '180', showOverflowTooltip: true },
          { title: '拒付状态', key: 'strIsDis', align: 'center', width: '180', showOverflowTooltip: true },
          { title: '冻结状态', key: 'strIsFrozen', align: 'center', width: '180', showOverflowTooltip: true },
          { title: '解冻状态', key: 'strIsThaw', align: 'center', width: '180', showOverflowTooltip: true },
          {
            title: '拒付金额', key: 'disAmount', align: 'center', width: '180', showOverflowTooltip: true, formatter(row, column, cellValue, index) {
              return row.mchTransCurrency + ' ' + (row.disAmount / 100).toFixed(2)
            }
          },
          {
            title: '退款金额', key: 'refundAmount', align: 'center', width: '180', showOverflowTooltip: true, formatter(row, column, cellValue, index) {
              return row.mchTransCurrency + ' ' + (row.refundAmount / 100).toFixed(2)
            }
          },
          {
            title: '冻结金额', key: 'frozenAmount', align: 'center', width: '180', showOverflowTooltip: true, formatter(row, column, cellValue, index) {
              return row.mchTransCurrency + ' ' + (row.frozenAmount / 100).toFixed(2)
            }
          },
          {
            title: '解冻金额', key: 'thawAmount', align: 'center', width: '180', showOverflowTooltip: true, formatter(row, column, cellValue, index) {
              return row.mchTransCurrency + ' ' + (row.thawAmount / 100).toFixed(2)
            }
          },
          // {title: '银行交易金额', key: 'bankTransAmount', align: 'center', width: '120', showOverflowTooltip: true, formatter(row, column, cellValue, index) {
          //   return row.bankCurrency + ' ' + row.bankTransAmount / 100
          // }},
          // {title: '商户结算金额', key: 'settleAmount', align: 'center', width: '120', showOverflowTooltip: true, formatter(row, column, cellValue, index) {
          //   return row.settleCurrency + ' ' + row.settleAmount / 100
          // }},
          // { title: '卡种', key: 'cardType', align: 'center', showOverflowTooltip: true },
          // { title: '卡号', key: 'cardNo', align: 'center', width: '180', showOverflowTooltip: true },
          { title: 'IP', key: 'ipAddress', align: 'center', width: '180', showOverflowTooltip: true },
          // { title: '邮箱', key: 'email', align: 'center', width: '180', showOverflowTooltip: true },
          { title: '交易通道', key: 'channelName', align: 'center', showOverflowTooltip: true },
          // { title: '是否勾兑', key: 'strIsChecked', align: 'center', showOverflowTooltip: true },
          // {title: '拒付预警费', key: 'disWarnFee', align: 'center', width: '180', showOverflowTooltip: true, formatter(row, column, cellValue, index) {
          //   return row.isDis == 2 ? row.mchTransCurrency + ' ' + (row.disWarnFee / 100) : '-'
          // }},
        ],
        rowHandle: {
          width: '250',
          align: 'center',
          fixed: 'right',
          custom: [
            {
              text: '查看订单',
              type: 'primary',
              size: 'mini',
              emit: 'custom-emit-handle-order'
            },
            {
              text: '变更日志',
              type: 'default',
              size: 'mini',
              emit: 'custom-emit-handle-order-log'
            }
          ]
        },
        list: [],
        pagination: {
          currentPage: 1,
          pageSize: 10,
          total: 0,
          pageSizes: [10, 50, 100, 200]
        },
        selectionRow: [],
      },
      rowInfo: {
        isDis: null,
        isFrozen: null
      },
      isCheckedOptions: isCheckedOptions,
      isRefundOptions: isRefundOptions,
      isFrozenOptions: isFrozenOptions,
      isShipOptions: isShipOptions,
      isSettleOptions: isSettleOptions,
      isDisOptions: isDisOptions,
      isThawOptions: isThawOptions,
      channelIdOptions: [],
      dateTimeRange: []
    }
  },
  mounted() {
    this.fetchChannelOptions();
    this.resetMainData();
  },
  beforeDestroy() {
  },
  methods: {
    // isDis: 0
    // isFrozen: 1
    // isRefund: 0
    // isSettle: 2
    // isThaw: 0
    // strIsDis: "未拒付"
    // strIsFrozen: "待审核"
    // strIsRefund: "未退款"
    // strIsSettle: "已结算"
    // strIsThaw: "未解冻"
    handleSearch() {
      this.mainTable.pagination.currentPage = 1;
      this.fetchMainData();
    },

    renderMainData(re) {
      this.mainTable.list = re.list;
      this.mainTable.pagination.total = re.total;
    },

    handleMainSizeChange(val) {
      this.mainTable.pagination.pageSize = val;
      this.mainTable.pagination.currentPage = 1;
      this.fetchMainData()
    },
    handleMainPageChange(val) {
      this.mainTable.pagination.currentPage = val;
      this.fetchMainData()
    },

    buildMainQuery() {

      var query = {
        page: this.mainTable.pagination.currentPage,
        limit: this.mainTable.pagination.pageSize,
        search: this.mainQuery,
      };

      return query;
    },

    resetMainData() {

      this.mainQuery = {
        mchNo: undefined,
        // terNo: undefined,
        tradeNo: undefined,
        isRefund: undefined,
        // isChecked: 2,
        isSettle: 2,
        isShip: undefined,
        isDis: undefined,
        isFrozen: undefined,
        isThaw: undefined,
        channelId: undefined,
        cardType: undefined,
        transStatus: undefined,
        cardEmail: undefined,
        cardFullName: undefined,
        cardFullPhone: undefined,
        ipAddress: undefined,
        startTime: undefined,
        endTime: undefined,
      };

      this.fetchMainData();
    },

    fetchChannelOptions() {
      ChannelApiMain.option().then(re => {
        this.channelIdOptions = re;
      })
    },

    async fetchMainData() {

      this.mainTable.loading = true;

      try {
        var re = await ApiMain.list(this.buildMainQuery());
        this.renderMainData(re);
      } catch (err) { }

      this.mainTable.loading = false;

    },

    onDateTimePickerChange() {
      this.mainQuery.startTime = this.dateTimeRange && this.dateTimeRange.length > 0 ? this.dateTimeRange[0] : ''
      this.mainQuery.endTime = this.dateTimeRange && this.dateTimeRange.length > 0 ? this.dateTimeRange[1] : ''
    },

    onMainCurrentChange(now, old) {
      console.log(now)
      if (!now) return
      this.mainTable.current = now;
      this.rowInfo = now
      this.getRowStart()
    },

    onMainDoubleClick(now) {
      this.mainTable.current = now;
      this.rowInfo = now
      this.getRowStart()
      this.handleSet();
    },

    getRowStart() {
      //  这里做一个处理 
      // startType  0 都可以  1 拒付 2 冻结 3 解冻 4 退款
      // auditType  0 都不显示 1 初审 2复审
      if (this.rowInfo.isDis != 0 && this.rowInfo.isDis != 3 && this.rowInfo.isDis != 5) {
        this.startType = 1
        this.startTypeText = 'dis'
        if (this.rowInfo.isDis == 1) {
          this.auditType = 1
        } else if (this.rowInfo.isDis == 2) {
          this.auditType = 2
        } else {
          this.auditType = 0
        }
      } else if (this.rowInfo.isFrozen != 0 && this.rowInfo.isFrozen != 3 && this.rowInfo.isFrozen != 5) {
        this.startType = 2
        this.startTypeText = 'frozen'
        if (this.rowInfo.isFrozen == 1) {
          this.auditType = 1
        } else if (this.rowInfo.isFrozen == 2) {
          this.auditType = 2
        } else if (this.rowInfo.isFrozen == 4) {
          // 通过了 可以解冻
          this.startType = 3
          this.startTypeText = 'thaw'
          if (this.rowInfo.isThaw == 1) {
            this.auditType = 1
          } else if (this.rowInfo.isThaw == 2) {
            this.auditType = 2
          } else {
            this.auditType = 0
          }
        } else {
          this.auditType = 0
        }
      } else if (this.rowInfo.isThaw != 0 && this.rowInfo.isThaw != 3 && this.rowInfo.isThaw != 5 && this.rowInfo.isThaw !=4) {
        this.startType = 3
        this.startTypeText = 'thaw'
        if (this.rowInfo.isThaw == 1) {
          this.auditType = 1
        } else if (this.rowInfo.isThaw == 2) {
          this.auditType = 2
        } else {
          this.auditType = 0
        }
      } else if (this.rowInfo.isRefund != 0 && this.rowInfo.isRefund != 3 && this.rowInfo.isRefund != 5) {
        this.startType = 4
        this.startTypeText = 'refun'
        if (this.rowInfo.isRefund == 1) {
          this.auditType = 1
        } else if (this.rowInfo.isRefund == 2) {
          this.auditType = 2
        } else {
          this.auditType = 0
        }
      } else {
        this.startType = 0
        this.auditType = 0
      }




    },
    onMainSelectionChange(now, old) {
      this.mainTable.selectionRow = now
    },

    handleAdd() {
      this.$refs['dialog-add'].show();
    },

    handleSet() {

      if (this.mainTable.current) {
        this.$refs['dialog-detail'].show(this.mainTable.current.id);
      }
    },

    handleOrderDetail({ index, row }) {
      this.$refs['dialog-detail'].show(row.id);
    },

    handleOrderLog({ index, row }) {
      this.$refs['dialog-log'].show(row.id);
    },
    handleAudit(startType) {
      this.$refs['dialog-audit'].show(this.mainTable.current.tradeNo, startType, this.startType, this.startTypeText);
    },
    // 退款
    handleRefund() {
      if (this.mainTable.current) {
        if (this.mainTable.current.isRefund == 1) {
          this.$message({ message: '已发起退款的请勿重复操作', type: 'warning' });
          return;
        }
        if (this.mainTable.current.isDis == 1) {
          this.$message({ message: '已发起拒付的请勿操作退款', type: 'warning' });
          return;
        }
        if (this.mainTable.current.isDis == 2) {
          this.$message({ message: '已拒付的请勿操作退款', type: 'warning' });
          return;
        }
        if (this.mainTable.current.isFrozen == 1) {
          this.$message({ message: '已发起冻结的请勿操作退款', type: 'warning' });
          return;
        }
        if (this.mainTable.current.isFrozen == 2) {
          this.$message({ message: '已冻结的请勿操作退款', type: 'warning' });
          return;
        }
        this.$refs['dialog-refund'].show(this.mainTable.current.tradeNo);
      } else {
        this.$message({ message: '请选择一行数据', type: 'warning' });
      }
    },

    // 拒付
    handleDis() {
      if (this.mainTable.current) {
        if (this.mainTable.current.isDis == 1) {
          this.$message({ message: '已发起拒付的请勿重复操作', type: 'warning' });
          return;
        }
        if (this.mainTable.current.isDis == 2) {
          this.$message({ message: '只能操作未拒付的订单', type: 'warning' });
          return
        }
        if (this.mainTable.current.isFrozen == 1) {
          this.$message({ message: '已发起冻结的请勿操作拒付', type: 'warning' });
          return;
        }
        if (this.mainTable.current.isFrozen == 2) {
          this.$message({ message: '已冻结的请勿操作拒付', type: 'warning' });
          return;
        }
        if (this.mainTable.current.isRefund == 1) {
          this.$message({ message: '已发起退款的请勿操作拒付', type: 'warning' });
          return;
        }
        if (this.mainTable.current.mchTransAmount == this.mainTable.current.refundAmount && this.mainTable.current.refundAmount > 0) {
          this.$message({ message: '已全部退款的请勿操作拒付', type: 'warning' });
          return;
        }
        this.$refs['dialog-dis'].show(this.mainTable.current.tradeNo);
      } else {
        this.$message({ message: '请选择一行数据', type: 'warning' });
      }
    },

    // 冻结
    handleFrozen() {
      if (this.mainTable.current) {
        if (this.mainTable.current.isFrozen == 1) {
          this.$message({ message: '已发起冻结的请勿重复操作', type: 'warning' });
          return;
        }
        if (this.mainTable.current.isFrozen == 2) {
          this.$message({ message: '只能操作未冻结的订单', type: 'warning' });
          return
        }
        if (this.mainTable.current.isDis == 1) {
          this.$message({ message: '已发起拒付的请勿操作冻结', type: 'warning' });
          return;
        }
        if (this.mainTable.current.isDis == 2) {
          this.$message({ message: '已拒付的请勿操作冻结', type: 'warning' });
          return
        }
        if (this.mainTable.current.isRefund == 1) {
          this.$message({ message: '已发起退款的请勿操作拒付', type: 'warning' });
          return;
        }
        if (this.mainTable.current.mchTransAmount == this.mainTable.current.refundAmount && this.mainTable.current.refundAmount > 0) {
          this.$message({ message: '已全部退款的请勿操作拒付', type: 'warning' });
          return;
        }
        this.$refs['dialog-frozen'].show(this.mainTable.current.tradeNo);
      } else {
        this.$message({ message: '请选择一行数据', type: 'warning' });
      }
    },

    // 解冻
    handleThaw() {
      if (this.mainTable.current) {
        this.$refs['dialog-thaw'].show(this.mainTable.current.tradeNo);
      } else {
        this.$message({ message: '请选择一行数据', type: 'warning' });
      }
    },

    // 解冻审核
    handleThawReview(handleStatus) {
      if (!this.mainTable.current) {
        this.$message({ message: '请选择一行数据', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isThaw == 0) {
        this.$message({ message: '还没提交解冻申请，不能进行解冻审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isFrozen != 2) {
        this.$message({ message: '该订单没有被冻结，请勿操作解冻审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isDis == 1) {
        this.$message({ message: '已发起拒付的请勿操作解冻审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isDis == 2) {
        this.$message({ message: '已拒付的请勿操作解冻审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isRefund == 1) {
        this.$message({ message: '已发起退款的请勿操作解冻审核', type: 'warning' });
        return;
      }
      this.$confirm('确定操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.doHandleThawReview(this.mainTable.current.tradeNo, handleStatus)
      });
    },

    async doHandleThawReview(tradeNo, handleStatus) {
      await ThawApiMain.handleStatus({ tradeNos: tradeNo, handleStatus: handleStatus });
      this.$message({ message: '操作成功', type: 'success' });
      this.mainTable.current = [];
      this.rowInfo = {}
      this.fetchMainData();
    },

    // 冻结审核
    handleFrozenReview(handleStatus) {
      if (!this.mainTable.current) {
        this.$message({ message: '请选择一行数据', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isFrozen == 0) {
        this.$message({ message: '还没提交冻结申请，不能进行冻结审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isFrozen == 2 || this.mainTable.current.isFrozen == 3) {
        this.$message({ message: '已复核冻结的请勿重复操作', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isDis == 1) {
        this.$message({ message: '已发起拒付的请勿操作冻结审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isDis == 2) {
        this.$message({ message: '已拒付的请勿操作冻结审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isRefund == 1) {
        this.$message({ message: '已发起退款的请勿操作冻结审核', type: 'warning' });
        return;
      }
      this.$confirm('确定操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.doHandleFrozenReview(this.mainTable.current.tradeNo, handleStatus)
      });
    },

    async doHandleFrozenReview(tradeNo, handleStatus) {
      await FrozenApiMain.handleStatus({ tradeNos: tradeNo, handleStatus: handleStatus });
      this.$message({ message: '操作成功', type: 'success' });
      this.mainTable.current = [];
      this.rowInfo = {}
      this.fetchMainData();
    },

    // 拒付审核
    handleDisReview(handleStatus) {
      if (!this.mainTable.current) {
        this.$message({ message: '请选择一行数据', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isDis == 0) {
        this.$message({ message: '还没提交拒付申请，不能进行拒付审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isDis != 1) {
        this.$message({ message: '已复核拒付的请勿重复操作', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isFrozen == 1) {
        this.$message({ message: '已发起冻结的请勿操作拒付审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isFrozen == 2 && this.mainTable.current.isThaw != 2) {
        this.$message({ message: '已冻结的请勿操作拒付审核', type: 'warning' });
        return;
      }
      if (this.mainTable.current.isRefund == 1) {
        this.$message({ message: '已发起退款的请勿操作拒付审核', type: 'warning' });
        return;
      }
      this.$confirm('确定操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.doHandleDisReview(this.mainTable.current.tradeNo, handleStatus)
      });
    },

    async doHandleDisReview(tradeNo, handleStatus) {
      await DisApiMain.handleStatus({ tradeNos: tradeNo, handleStatus: handleStatus });
      this.$message({ message: '操作成功', type: 'success' });
      this.mainTable.current = [];
      this.rowInfo = {}
      this.fetchMainData();
    },

    handleUpload() {
      this.$refs['dialog-upload'].show();
    },

    handleUploadReview() {
      this.$refs['dialog-review'].show();
    },

    // 拒付预警
    handleIsDisWarnFee() {
      if (this.mainTable.selectionRow.length == 0) {
        this.$message({ message: '请选择行', type: 'error' });
        return;
      }

      // 检查是否符合条件
      let tradeNos = [];
      for (var i in this.mainTable.selectionRow) {
        if (this.mainTable.selectionRow[i].isDis == 2) {
          this.$message({ message: '已经拒付，不能操作拒付预警', type: 'error' });
          return;
        }
        if (this.mainTable.selectionRow[i].isDisWarnFee == 1) {
          this.$message({ message: '已经拒付预警', type: 'error' });
          return;
        }
        tradeNos.push(this.mainTable.selectionRow[i].tradeNo);
      }

      this.$confirm('确定对选中的订单进行拒付预警操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.doIsDisWarnFee(tradeNos.join(','))
      });
    },

    async doIsDisWarnFee(tradeNos) {
      await ApiMain.handldIsDisWarnFee({ tradeNos: tradeNos });
      this.$message({ message: '操作成功', type: 'success' });
      this.fetchMainData();
    },

  }
}
</script>

<style>
</style>
